import districts from './districts.json' 

export let district = districts
export function code2str(province, city, county) {
  let provinceStr = province?(districts[100000][province]):''
  let cityStr = city?(districts[province]&&districts[province][city]):''
  let countyStr = county?(districts[city]&&districts[city][county]):''
  return [provinceStr, cityStr, countyStr]
}

export function getCitys() {
  let cityList = []
  let keys = []
  Object.keys(districts).forEach((key) => {
    let top2Str = key.slice(0,2)
    if (Number(top2Str)>12 && (String(key)).endsWith('0000')) {
      Object.keys(districts[key]).forEach((cityKey) => {
        cityList.push({key:key,value: districts[key][cityKey]})
      })
    }
  })
  cityList = [
    {key:110000, value: '北京市'},
    {key:120000, value: '天津市'},
    {key:310000, value: '上海市'},
    {key:500000, value: '重庆市'},
    {key:810000, value: '香港特别行政区'},
    {key:820000, value: '澳门特别行政区'},
    ...cityList,
  ]
  cityList = cityList.map(v=>v.value)
  
  cityList.sort((a, b)=> {
    return a.localeCompare(b, 'zh-Hans-CN', { sensitivity: 'accent' })
  })

  return cityList
}